package com.ketai.appinfo.intercepter;
import com.ketai.appinfo.pojo.DevUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         // 登录拦截
        DevUser sessionUser=(DevUser) request.getSession().getAttribute("devUserSession");
        if (sessionUser==null){
            response.sendRedirect("../devlogin.jsp");
            return false;
        }

        // 对登录路径进行判断
        String  path=request.getServletPath();
              if (!path.contains("dev")){
                  response.sendRedirect("/403.jsp");
                  return  false;
              }

            return  true;
        }
}
